package com.fyt.ZhongYaoApp.mapper;

import com.fyt.ZhongYaoApp.pojo.ZY;
import com.fyt.ZhongYaoApp.pojo.vo.ZYQuerry;
import com.fyt.ZhongYaoApp.pojo.vo.ZYVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ZYMapper {

    @Insert("insert into zy(`name`, `alias`, `eng_name`, `cat_id`, `characteristic`, `usage`, `effect`, `location`,`amount`)" +
            "values (#{name},#{alias},#{engName},#{catId},#{characteristic},#{usage},#{effect},#{location},#{amount})")
    void add(ZY zy);

    @Select("SELECT" +
            "  `z`.`id`," +
            "  `z`.`name`," +
            "  `z`.`alias`," +
            "  `z`.`eng_name`," +
            "  `c`.`cat_name`," +
            "  `z`.`characteristic`," +
            "  `z`.`usage`," +
            "  `z`.`effect`," +
            "  `z`.`zy_pic`," +
            "  `z`.`location`," +
            "  `z`.`url`," +
            "   z.amount " +
            "FROM" +
            "  `zy` AS z" +
            "    LEFT JOIN `zy_cat` AS c ON `z`.`cat_id` = `c`.`id`" +
            "WHERE" +
            "  1 = 1")
    List<ZYQuerry> ZYList();

//    @Select("SELECT" +
//            "  `z`.`id`," +
//            "  `z`.`name`," +
//            "  `z`.`alias`," +
//            "  `z`.`eng_name`," +
//            "  `c`.`cat_name`," +
//            "  `z`.`characteristic`," +
//            "  `z`.`usage`," +
//            "  `z`.`effect`," +
//            "  `z`.`zy_pic`," +
//            "  `z`.`location`," +
//            "  `z`.`url`" +
//            "FROM" +
//            "  `zy` AS z" +
//            "    LEFT JOIN `zy_cat` AS c ON `z`.`cat_id` = `c`.`id`" +
//            "WHERE" +
//            " `z`.`cat_id` = #{catId}")
    List<ZYQuerry> ZYListByCat(ZY zy);

    @Select("SELECT" +
            "  `z`.`id`," +
            "  `z`.`name`," +
            "  `z`.`alias`," +
            "  `z`.`eng_name`," +
            "  `c`.`cat_name`," +
            "  `z`.`characteristic`," +
            "  `z`.`usage`," +
            "  `z`.`effect`," +
            "  `z`.`zy_pic`," +
            "  `z`.`location`," +
            "  `z`.`url`," +
            " `z`.`amount`" +
            "FROM" +
            "  `zy` AS z" +
            "    LEFT JOIN `zy_cat` AS c ON `z`.`cat_id` = `c`.`id`" +
            "WHERE" +
            " `z`.`cat_id` = #{id}")
    ZYQuerry zyFindByCatId(Integer id);


    @Select("SELECT" +
            "  `z`.`id`," +
            "  `z`.`name`," +
            "  `z`.`alias`," +
            "  `z`.`eng_name`," +
            "  `c`.`cat_name`," +
            "  `z`.`characteristic`," +
            "  `z`.`usage`," +
            "  `z`.`effect`," +
            "  `z`.`zy_pic`," +
            "  `z`.`location`," +
            "  `z`.`url`," +
            " `z`.`amount`," +
            " z.growth_url ," +
            " z.process_url " +
            "FROM" +
            "  `zy` AS z" +
            "    LEFT JOIN `zy_cat` AS c ON `z`.`cat_id` = `c`.`id`" +
            "WHERE" +
            " `z`.`id` = #{id}")
    ZYQuerry zyFindById(Integer id);

    /**
     * 根据种类查询部分中药信息
     * @param zy
     * @return
     */
//    @Select("SELECT" +
//            "  `z`.`id`," +
//            "  `z`.`name`," +
//            "  `z`.`characteristic`," +
//            "  `z`.`zy_pic`" +
//            "FROM" +
//            "  `zy` AS z" +
//            "    LEFT JOIN `zy_cat` AS c ON `z`.`cat_id` = `c`.`id`" +
//            "WHERE" +
//            " `z`.`cat_id` = #{catId}")
    List<ZYVO> ZYListPartByCat(ZY zy);
}
